/*
 * TCSS 422 - Spring quarter 2011
 * Team: 	Googlers
 * Members: Deepa Sahni, Krisnil Gounder, Michael Schweiger
 * Date: 	April 8, 2011
 */
package testing;

import java.util.HashSet;

import org.junit.Test;

import ui.ConsoleReporter;
import ui.Reporter;
import web.Gatherer2;
import web.PageParser;

/**
 * This is a test class to ensure page is parsed properly.
 * 
 * @author Krisnil Gounder
 * @version April 12th, 2011
 *
 */
public class PageParserUnitTest {
	
	/**
	 * Parser.
	 */
	private PageParser parser;
	
	/**
	 * The following method tests the page parser, for most likely cases of
	 * html format.
	 */
	@Test
	public void testPageParser() {

		String testPage = "testPage <html> <body> <h1>My First Heading</h1> <p> My first paragraph.</p> </body> </html> " +
				"<html> <body> <!--This comment will not be displayed--> <p>" +
				"This is a regular paragraph</p> </body> </html> <html> <body> " +
				"<a href=" +
				"http://www.w3schools.com" +
				">This is a link</a> </body> </html>" +
				"<a href=" + 
				"mailto:homer@example.com" + 
				">Send an email to Homer now!</a>";
				

		String notLink = "im not a link";
		String linkTestPage = "<a href=" +
							  "http://www.quackit.com/html/codes" +
							  ">Get your HTML codes here!</a>";
		String testURL = "http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Matcher.html";
		
		Reporter reporter = new ConsoleReporter();
		Gatherer2 gatherer = new Gatherer2(new HashSet<String>(), reporter);
		
		parser = new PageParser(testURL, gatherer, testPage);
		parser.run();
		System.out.println("After Parsing - ");
		parser.testOutput();
		System.out.println("Number of Links: " + parser.getNumOfLinks());
		System.out.println();
		
		parser = new PageParser(testURL, gatherer, linkTestPage); 
		parser.run();
		System.out.println("After Parsing - ");
		parser.testOutput();
		System.out.println("Number of Links: " + parser.getNumOfLinks());
		System.out.println();
	
		parser = new PageParser(testURL, gatherer, notLink);  
		parser.run();
		
		System.out.println("After Parsing - ");
		parser.testOutput();
		System.out.println("Number of Links: " + parser.getNumOfLinks());
		System.out.println();	
	}
}
